﻿namespace KingerRobot.MexicoSailunWMS.SpiService;
internal interface ITask
{
    /// <summary>
    /// 更改任务calldelete
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="calldelete"></param>
    void UpdateTaskCallDelete(long taskId, int calldelete);
    /// <summary>
    /// 根据订单明细获取任务
    /// </summary>
    /// <param name="summaryId"></param>
    /// <returns></returns>
    POWcsTask GetTasksBySummaryId(long summaryId);
    /// <summary>
    /// 删除当前任务的SKU库位绑定信息
    /// </summary>
    /// <param name="task"></param>
    /// <returns></returns>
    int DeleteBindLocInfoByTask(POWcsTask task);
    /// <summary>
    /// 根据订单MastId获取任务信息
    /// </summary>
    /// <param name="masterId">订单Id</param>
    /// <returns></returns>
    List<POWcsTask> GetTasksByMasterId(long masterId);
    /// <summary>
    /// 修改任务类型
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <param name="type">类型</param>
    void EditTaskType(long taskId, int type);
    /// <summary>
    /// 创建出库输送线异常任务
    /// </summary>
    /// <param name="startLoc">扫描库位</param>
    /// <param name="skuId"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    long CreateOutAbnormalTask(long startLoc, long skuId, string remark);
    /// <summary>
    /// 通过taskId获取任务信息
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns>任务信息</returns>
    POWcsTask GetTaskByTaskId(long taskId);
    /// <summary>
    /// 通过任务获取目标位置
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns></returns>
    long GetTargetIdByTaskId(long taskId);
    /// <summary>
    /// 通过taskId获取"已下发"状态任务
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    POWcsTask GetExecutedTaskByTaskId(long taskId);
    /// <summary>
    /// 获取上一次执行的任务
    /// </summary>
    /// <param name="locId">设备库位</param>
    /// <param name="type">任务类型</param>
    /// <returns></returns>
    POWcsTask GetLastTaskByLocId(long locId, int type);
    /// <summary>
    /// 通过 skuId 获取任务列表
    /// </summary>
    /// <param name="skuIds"></param>
    /// <returns></returns>
    List<POWcsTask> GetTaskBySkuIds(List<long?> skuIds);
    /// <summary>
    /// 通过 skuId 获取任务
    /// </summary>
    /// <param name="skuId"></param>
    /// <returns></returns>
    POWcsTask GetTaskBySkuId(long skuId);
    /// <summary>
    /// 通过类型查询任务
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    List<POWcsTask> GetTaskByType(int type);
    /// <summary>
    /// 获得所有任务
    /// </summary>
    /// <returns></returns>
    List<POWcsTask> GetTaskList();
    /// <summary>
    /// 获取所有任务产品信息
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    List<TaskProductBean> GetTaskProduct();
    /// <summary>
    ///  获取所有出库/入库 未执行任务
    /// </summary>
    /// <returns></returns>
    List<POWcsTask> GetIOExecutableWcsTasksByType(EnumTaskType enumTaskType);
    /// <summary>
    /// 通过locId获取可执行任务
    /// </summary>
    /// <param name="locId">位置ID</param>
    /// <returns>任务信息</returns>
    POWcsTask GetExecutableTaskByLocId(long locId);
    /// <summary>
    /// 通过locId获取可执行任务TaskId
    /// </summary>
    /// <param name="locId">位置ID</param>
    /// <returns>任务信息</returns>
    long GetExecutableTaskIdkByLocId(long locId);

    /// <summary>
    /// 通过taskNo获取任务信息
    /// </summary>
    /// <param name="taskNo">任务号</param>
    /// <returns>任务信息</returns>
    POWcsTask GetTaskByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取"可下发"状态任务
    /// </summary>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    POWcsTask GetExecutableTaskByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取"已分配库位"状态任务
    /// </summary>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    POWcsTask GetDistributionLocByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取"执行入库"状态任务
    /// </summary>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    POWcsTask GetExecutedByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取"已下发"状态任务
    /// </summary>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    POWcsTask GetExecutedTaskByTaskNo(int taskNo);
    /// <summary>
    /// 删除任务
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns></returns>
    int DeleteTask(long taskId);
    /// <summary>
    /// 备份任务
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int BakTask(long taskId);
    /// <summary>
    /// 备份并删除任务和命令
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int BakAndDeleteTaskAndCmd(long taskId);
    /// <summary>
    /// 备份并删除任务
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int BakAndDeleteTask(long taskId);

    /// <summary>
    /// 通过产品条码获取任务信息
    /// </summary>
    /// <param name="productCode">产品条码</param>
    /// <returns>任务信息（包含任务、任务命令）</returns>
    POWcsTask GetTaskByProductCode(string productCode);

    /// <summary>
    /// 通过产品条码获取任务是否存在
    /// </summary>
    /// <param name="productCode">产品条码</param>
    /// <returns>true:存在；false:不存在</returns>
    bool HasTaskByProductCode(string productCode);

    /// <summary>
    /// 通过产品条码获取任务ID
    /// </summary>
    /// <param name="productCode">产品条码</param>
    /// <returns>任务ID</returns>
    long GetTaskIdByProductCode(string productCode);

    /// <summary>
    /// 通过产品条码删除任务
    /// </summary>
    /// <param name="productCode">产品条码</param>
    /// <returns>任务ID</returns>
    int DelTaskIdByProductCode(string productCode);

    /// <summary>
    /// 通过目标位置获取所有任务
    /// </summary>
    /// <param name="targetLoc">目标位置Id</param>
    /// <returns>任务集合</returns>
    List<POWcsTask> GetAllTasksByTargetLoc(long targetLoc);

    /// <summary>
    /// 通过目标位置获取任务数量
    /// </summary>
    /// <param name="targetLoc">目标位置Id</param>
    /// <returns>任务数量</returns>
    int GetTaskCountByTargetLoc(long targetLoc);


    /// <summary>
    /// 通过目标位置获取是否有任务
    /// </summary>
    /// <param name="targetLoc">目标位置Id</param>
    /// <returns>是否有任务</returns>
    bool GetHasTaskByTargetLoc(long targetLoc);



    /// <summary>
    /// 修改任务状态
    /// </summary>
    /// <param name="locId">当前位置</param>
    /// <param name="taskId">任务ID</param>
    /// <param name="status">状态</param>
    int UpdateTaskStatus(long locId, long taskId, int status);

    /// <summary>
    /// 集合修改状态
    /// </summary>
    /// <param name="taskIds"></param>
    /// <param name="status"></param>
    /// <returns></returns>
    int UpdateTaskAndCmdStatusByTaskIds(List<long> taskIds, int status);

    /// <summary>
    /// 修改任务喷涂
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int UpdateTaskSpray(long taskId, int isSpray);
    /// <summary>
    /// 修改备注
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    int UpdateTaskReamrkByTaskId(long taskId, string remark);
    /// <summary>
    /// 修改任务和命令状态
    /// </summary>
    /// <param name="locId">当前位置</param>
    /// <param name="taskId">任务ID</param>
    /// <param name="status">状态</param>
    int UpdateTaskAndCmdStatus(long locId, long taskId, int status);
    /// <summary>
    /// 修改任务和命令状态(手工)
    /// </summary>
    /// <param name="locId">当前位置</param>
    /// <param name="taskId">任务ID</param>
    /// <param name="status">状态</param>
    int UpdateTaskAndCmdStatusForManualEnd(long locId, long taskId, int status);

    /// <summary>
    /// 目标位置任务汇总
    /// </summary>
    /// <returns>目标汇总数量</returns>
    List<TaskGroupCount> GetTargetLocTaskGroup();
    /// <summary>
    /// 物料任务汇总
    /// </summary>
    /// <returns>物料汇总数量</returns>
    List<TaskGroupCount> GetMaterialTaskGroup();

    /// <summary>
    /// 开始任务汇总
    /// </summary>
    /// <returns>开始放货位汇总数量</returns>
    List<TaskGroupCount> GetStartLocTaskGroup();

    /// <summary>
    /// 通过设备查询是否有未完成任务
    /// </summary>
    /// <param name="equipId">设备Id</param>
    /// <returns>是否有任务</returns>
    bool IsTaskByEquipId(long equipId);
    /// <summary>
    /// 通过任务ID修改目标货位
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <param name="targetLoc">目标货位</param>
    /// <returns></returns>
    int UpdateTaskTargetLoc(long taskId, long targetLoc);
    /// <summary>
    /// 根据组号获取任务列表
    /// </summary>
    /// <param name="groupNo">组号</param>
    /// <returns></returns>
    List<POWcsTask> GetTasksByGroupNo(long groupNo);

    /// <summary>
    /// 通过 taskId 获取物料ID
    /// </summary>
    /// <param name="taskIds"></param>
    /// <returns></returns>
    List<TaskMaterial> GetTaskMaterial(List<long?> taskIds);

    /// <summary>
    /// 获取任务状态
    /// </summary>
    /// <returns></returns>
    List<Spi.TaskStatus> GetTaskStatus();

    /// <summary>
    /// 获取任务管理视图
    /// </summary>
    /// <returns></returns>
    List<POVTasks> GetVTasks();

    List<POVTasks> GetVTasksOrderBy(string OrderByType, string OrderByName);
}
internal class TaskInfoBean
{
    public POWcsTask POWcsTask { get; set; }
    public POWcsTaskCmd POWcsTaskCmd { get; set; }
}
internal class TaskProductBean
{
    public POWcsTask POWcsTask { get; set; }
    public POProdProduct POProdProduct { get; set; }
}

internal class SkuProductBean
{
    public POProdSkuProduct POProdSkuProduct { get; set; }

    public POProdProduct POProdProduct { get; set; }
}

internal class TaskMaterial
{
    public long TaskId { get; set; }
    public long MaterialId { get; set; }
}

internal class TaskGroupCount
{
    public int Count { get; set; }
    public long? LocId { get; set; }
}

